package mosdi.tests;

import java.util.ArrayList;

import junit.framework.TestCase;
import mosdi.paa.DAA;
import mosdi.paa.apps.UnconstrainedCpGDAA;
import mosdi.util.Alphabet;
import mosdi.util.CodonAlphabet;
import static org.junit.Assert.assertArrayEquals;

public class UnconstrainedCpGDAATest extends TestCase {
	
	public void testCounting() {
		Alphabet alphabet = Alphabet.getDnaAlphabet();
		int[] text = CodonAlphabet.dnaToCodonText(alphabet.buildIndexArray("GCGTCGATGTGTGTTTGAGACGTGGGAACCGTTTCACCATGTCTCAATGAGCCCTCCTAGACGTTATATGGCGACAGTCTGTGGAGAAGACCACTGCCTCATCGTTCAAACTTGAGGAAAGTTGCCACCATCAATGCATGCACGTCTGAAACATGGGACGCTCGAACGCTTTTGAGTTGTGATTTATATCTTGCCGCAACGAAGACATCCCCGAGTCTTTAAGTTCAACATTGCCTTCTTAAAAGCCCGATCTTGCATGCCTACTCAGAAGTTATATGTTAAGGGATGTTCTACGACGCGGAGATTAGATTGTTGAGCGGCCTATATAGTAGCCGTGCATACAGGTAGATCAGGGTACGCAACTTGGCTAATAATCCGACAGATTCCGCATTGTATCTGCTTTAATTGGATTACCGCGTGGCGCTCCCTCCGCGTGGTGAACCGACACGTCTTCCTTAACCCTAAATAGAGAGACGCCGCTCGCATATCGTAGGTAGAACTACCTTAAATGGCAGGGACAATCATATCCCACAAAGTAAGTCTCATTTCACAAGAAGTGGTTTCTGCACAATATCATGATTATTTCTAAGTGCAGACATGAAGGTCCCGCTACCACGGCGTCAAACTCGGACTAGACGTCTCGGTTCAACAGCGTTCCGGCTACACCCCACCTGATATTCCCTGCTTGAAGCCTTAGCGGTTATCTGTGTCTCCTACTATATTCTGCAGTCTTGACCCCTACAACTGCGAACTCCAGTTCACTCACGGGTGCGGGAATTACGGTGTGTCAGGCGTGGGGTCCCTGATAGTCCTAGGCTTGTAAGAATGAACGTATAAGAGGCGATAGCAGCCTTGCAATATTGCAAGGTACAGCGCAAGATTGACGATAAGTGAGGTATAGGGCAATCGCGAGTTTAACCGTGCGGTCGGGCTTCTATTAGCGTCACGTCCTACACTCTGCCTTAAAGGGGGTTCACTGATAAATGCCCAATTAAAGAG"));
		DAA daa = new UnconstrainedCpGDAA(100);
		assertEquals(37, daa.computeValue(text));
		Integer[] expected = {0, 1, 7, 10, 20, 24, 47, 53, 55, 65, 66, 70, 82, 98, 99, 99, 106, 125, 129, 139, 140, 143, 147, 160, 163, 202, 214, 217, 232, 277, 280, 295, 302, 306, 308, 314, 315};
		ArrayList<Integer> actual = new ArrayList<Integer>();
		int state = daa.getStartState();
		int n = 0;
		for (int c : text) {
			state = daa.getTransitionTarget(state, c);
			for (int i=0; i<daa.getEmission(state); ++i) {
				actual.add(n);
			}
			n +=1 ;
		}
		assertArrayEquals(expected, actual.toArray());
	}

	public void testCountingOnlyFrame2() {
		Alphabet alphabet = Alphabet.getDnaAlphabet();
		int[] text = CodonAlphabet.dnaToCodonText(alphabet.buildIndexArray("GCGTCGATGTGTGTTTGAGACGTGGGAACCGTTTCACCATGTCTCAATGAGCCCTCCTAGACGTTATATGGCGACAGTCTGTGGAGAAGACCACTGCCTCATCGTTCAAACTTGAGGAAAGTTGCCACCATCAATGCATGCACGTCTGAAACATGGGACGCTCGAACGCTTTTGAGTTGTGATTTATATCTTGCCGCAACGAAGACATCCCCGAGTCTTTAAGTTCAACATTGCCTTCTTAAAAGCCCGATCTTGCATGCCTACTCAGAAGTTATATGTTAAGGGATGTTCTACGACGCGGAGATTAGATTGTTGAGCGGCCTATATAGTAGCCGTGCATACAGGTAGATCAGGGTACGCAACTTGGCTAATAATCCGACAGATTCCGCATTGTATCTGCTTTAATTGGATTACCGCGTGGCGCTCCCTCCGCGTGGTGAACCGACACGTCTTCCTTAACCCTAAATAGAGAGACGCCGCTCGCATATCGTAGGTAGAACTACCTTAAATGGCAGGGACAATCATATCCCACAAAGTAAGTCTCATTTCACAAGAAGTGGTTTCTGCACAATATCATGATTATTTCTAAGTGCAGACATGAAGGTCCCGCTACCACGGCGTCAAACTCGGACTAGACGTCTCGGTTCAACAGCGTTCCGGCTACACCCCACCTGATATTCCCTGCTTGAAGCCTTAGCGGTTATCTGTGTCTCCTACTATATTCTGCAGTCTTGACCCCTACAACTGCGAACTCCAGTTCACTCACGGGTGCGGGAATTACGGTGTGTCAGGCGTGGGGTCCCTGATAGTCCTAGGCTTGTAAGAATGAACGTATAAGAGGCGATAGCAGCCTTGCAATATTGCAAGGTACAGCGCAAGATTGACGATAAGTGAGGTATAGGGCAATCGCGAGTTTAACCGTGCGGTCGGGCTTCTATTAGCGTCACGTCCTACACTCTGCCTTAAAGGGGGTTCACTGATAAATGCCCAATTAAAGAG"));
		DAA daa = new UnconstrainedCpGDAA(100, false);
		assertEquals(16, daa.computeValue(text));
		Integer[] expected = {7, 10, 24, 53, 65, 98, 99, 106, 129, 139, 163, 214, 277, 295, 308, 314};
		ArrayList<Integer> actual = new ArrayList<Integer>();
		int state = daa.getStartState();
		int n = 0;
		for (int c : text) {
			state = daa.getTransitionTarget(state, c);
			for (int i=0; i<daa.getEmission(state); ++i) {
				actual.add(n);
			}
			n +=1 ;
		}
		assertArrayEquals(expected, actual.toArray());
	}

}
